$(document).ready( function() {
	$('body').layout();
	
	// tabs init with a custom tab template and an "add" callback filling in the content
	var $tabs = $("#tabs").tabs({
		cache: true,
		tabTemplate: "<li><a href='#{href}'>#{label}</a> <span class='ui-icon ui-icon-close'>Remove Tab</span></li>"
	});
	
	$( "#tabs span.ui-icon-close" ).live( "click", function() {
		var index = $( "li", $tabs ).index( $( this ).parent() );
		$tabs.tabs( "remove", index );
	});
});

function addTab(ndx) {
	var _exist = false;
	var _ndx = eval(ndx);
	
	var _urls = new Array();
	_urls[1] = "core/data.php";
	_urls[2] = "core/user.php";
	_urls[3] = "core/notice_list.php";

	var _imgs = new Array();
	_imgs[1] = "001_43.png";
	_imgs[2] = "001_57.png";
	_imgs[3] = "001_10.png";

	var _txts = new Array();
	_txts[1] = "데이터관리";
	_txts[2] = "사용자관리";
	_txts[3] = "공지사항";

	var _title = "<img src=\"assets/img/ico/" + _imgs[_ndx] + "\" style=\"width:20px;height:20px;border:none;\" />&nbsp;" + _txts[_ndx];
	
	$('#tabs li').each( function() {
		if($(this).html().indexOf(_imgs[_ndx]) > 0) {
			$('#tabs').tabs('select', $(this).index());
			_exist = true;
		}
	});

	if(!_exist) {
		$('#tabs').tabs('add', _urls[_ndx], _title);
		$('#tabs').tabs('select', $('#tabs').tabs('length')-1);
	}
}